/**
 * 基Activity，提供公用方法
 */
package net.youpo.Market;

import net.youpo.Market.Util.GlobalVariables;
import net.youpo.Market.db.MarketDatabase;
import android.app.Activity;
import android.view.KeyEvent;
import android.widget.Toast;

public class BaseActivity extends Activity {
    private boolean mExit_Flag;// 退出标记

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK: {
            if (mExit_Flag) {
                MarketDatabase.closeMarketDB();
                // Intent intent = new Intent(BaseActivity.this,
                // MessageService.class);
                // stopService(intent);//为了支持后台消息推送
                this.finish();
                GlobalVariables.IS_RUNNING = false;
                // System.exit(0);//为了支持后台消息推送
            } else {
                Toast.makeText(this, R.string.exit_tips, Toast.LENGTH_SHORT)
                        .show();
                mExit_Flag = true;
            }
            break;
        }
        default:
            super.onKeyDown(keyCode, event);
            return false;
        }
        return true;
    }
}
